package com.docking.heylo.web.controller;

import com.docking.heylo.dao.entity.SysResources;
import com.docking.heylo.service.ISysResourceService;
import com.docking.heylo.web.dto.SysResourcesDto;
import com.docking.heylo.web.utils.ResultUtil;
import com.docking.heylo.web.vo.BaseVo;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;


/****
 * 系统资源管理控制器
 *
 */
@RestController
@RequestMapping("/sysResource")
public class SysResourcesController {

    @Autowired
    private ISysResourceService resourceService;

    /***
     * 保存资源信息
     *
     * @param sysResources
     * @return
     */
    @RequestMapping("/saveResources")
    public BaseVo saveResources(@RequestBody SysResourcesDto sysResources){
        resourceService.saveResource(sysResources);
        return ResultUtil.success("成功");
    }

    /***
     * 资源列表
     *
     * @param resourcesInput
     * @return
     */
    @RequestMapping("/resourceList")
    public BaseVo resourceList(@RequestBody SysResourcesDto resourcesInput){
        PageInfo<Map<String, Object>> resourcesVo = resourceService.resourceList(resourcesInput);
        return ResultUtil.success("成功",resourcesVo);
    }


    /***
     * 资源信息
     *
     * @param resourcesDto
     * @return
     */
    @RequestMapping("/resourceInfo")
    public BaseVo resourceInfo(@RequestBody SysResourcesDto resourcesDto){
        SysResources dbResources = resourceService.selectById(resourcesDto.getId());
        return ResultUtil.success("成功",dbResources);
    }


    /***
     * 修改资源信息
     * @param resources
     * @return
     */
    @RequestMapping("/editResource")
    public BaseVo editResource(@RequestBody SysResourcesDto resources){
        resourceService.editResource(resources);
        return ResultUtil.success("成功");
    }

    /***
     * 删除资源
     *
     * @param resources
     * @return
     */
    @RequestMapping("/delResource")
    public BaseVo delResource(@RequestBody SysResourcesDto resources){
        resourceService.delResource(resources.getId());
        return ResultUtil.success("成功");
    }



}
